﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace XNASpelProjekt
{
    /// <summary>
    /// Basklass till alla spelets banor, inklusive startskärmen.
    /// </summary>
    class TitleScreen : Map
    {
        #region member variables

        private KeyboardState kbState;
        private int cursorpos;
        private Texture2D arrowImage;

        #endregion

        #region constructors
        public TitleScreen()
        {
            kbState = Keyboard.GetState();
            backgroundImage = Game1.titleImage;
            arrowImage = Game1.arrowImage;
        }

        #endregion

        #region public methods

        /// <summary>
        /// Updates the map, including all actors on the map
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            if(kbState.IsKeyDown(Keys.Up))
            {
                if (cursorpos > 0)
                {
                    cursorpos--;
                }
            }
            else if (kbState.IsKeyDown(Keys.Down))
            {
                if (cursorpos < 1)
                {
                    cursorpos++;
                }
            }
            else if (kbState.IsKeyDown(Keys.Enter))
            {
                switch (cursorpos)
                {
                    case 0:
                        Game1.map = new Level1();
                        break;
                    case 1:
                        Game1.quit = true;
                        break;
                    default:
                        break;
                }
            }
            kbState = Keyboard.GetState();
        }

        /// <summary>
        /// Draws the map, including all actors on the map
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// <param name="spriteBatch">A SpriteBatch is used to draw textures.</param>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //begin spriteBatch drawing
            spriteBatch.Begin();

            //Vector2 for specifying drawing position
            Vector2 drawPos = new Vector2(0, 0);

            //draw background 
            spriteBatch.Draw(backgroundImage, drawPos, Color.White);

            //draw cursor
            drawPos.X = 40;
            drawPos.Y = 373 + cursorpos * 20;
            spriteBatch.Draw(arrowImage, drawPos, Color.White);

            //end spriteBatch drawing
            spriteBatch.End();
        }

        #endregion
    }
}